Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports Microsoft.VisualBasic.PowerPacks
Namespace BMLERP
	Friend Class frmINV100
		Inherits System.Windows.Forms.Form
		Dim OldIMITN As String
		Private mintCurFrame As Short ' Current Frame visible

		Private Sub Control(ByRef GT As Object)
			cboIMTYP.Enabled = GT
			txtIMWUM.Enabled = GT
			txtIMVPU.Enabled = GT
			txtIMSDC.Enabled = GT
			txtIMITD.Enabled = GT
			txtIMETD.Enabled = GT
			txtIMWPU.Enabled = GT
			txtIMPER.Enabled = GT
			txtIMATC.Enabled = GT
			cboIMCLC.Enabled = GT
			cboIMUMC.Enabled = GT
			txtIMPGC.Enabled = GT
			' txtIMITN.Enabled = GT
			txtIMPRC.Enabled = GT
			txtIMLSZ.Enabled = GT
			txtIMROU.Enabled = GT
			txtIMOPC.Enabled = GT
			txtIMLTM.Enabled = GT
			txtIMVDC.Enabled = GT
			txtIMBSZ.Enabled = GT
			txtIMVTC.Enabled = GT
			txtRCED1.Enabled = GT
			txtRCED2.Enabled = GT
			txtRCED3.Enabled = GT
			txtRCVPU.Enabled = GT
			txtRCVUM.Enabled = GT
			txtRCPWG.Enabled = GT


			cboIMTYP.Locked = Not GT
			txtIMWUM.ReadOnly = Not GT
			txtIMVPU.ReadOnly = Not GT
			txtIMSDC.ReadOnly = Not GT
			txtIMITD.ReadOnly = Not GT
			txtIMETD.ReadOnly = Not GT
			txtIMWPU.ReadOnly = Not GT
			txtIMPER.ReadOnly = Not GT
			txtIMATC.ReadOnly = Not GT
			cboIMCLC.Locked = Not GT
			cboIMUMC.Locked = Not GT
			txtIMPGC.ReadOnly = Not GT
			'txtIMITN.Locked = Not GT
			txtIMPRC.ReadOnly = Not GT
			txtIMLSZ.ReadOnly = Not GT
			txtIMROU.ReadOnly = Not GT
			txtIMOPC.ReadOnly = Not GT
			txtIMLTM.ReadOnly = Not GT
			txtIMVDC.ReadOnly = Not GT
			txtIMBSZ.ReadOnly = Not GT
			txtIMVTC.ReadOnly = Not GT
			txtRCED1.ReadOnly = Not GT
			txtRCED2.ReadOnly = Not GT
			txtRCED3.ReadOnly = Not GT
			txtRCVPU.ReadOnly = Not GT
			txtRCVUM.ReadOnly = Not GT
			txtRCPWG.ReadOnly = Not GT
			cboIMITN.Enabled = Not GT
			cboIMITN.Locked = GT
		End Sub
		Private Sub cboIMCLC_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboIMCLC.ClickEvent
			If eventArgs.area = 2 Then
				' txtIMCLC = cboIMCLC.BoundText
				' txtCLDSC = cboIMCLC.Text
			End If
		End Sub

		Private Sub cboIMCLC_KeyPressEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_KeyPressEvent) Handles cboIMCLC.KeyPressEvent
			If eventArgs.keyAscii = 13 Then
				cboIMUMC.Focus()
			End If

		End Sub

		Private Sub cboIMITN_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cboIMITN.Change
			txtIMITN.Text = cboIMITN.BoundText
			txtRCITN.Text = cboIMITN.BoundText
			ISEDITING = False
			ButtonStatus()
			WriteToScreen((1))
			'cboIMITN.SelStart = 1
			cboIMITN.SelLength = 0
		End Sub

		Private Sub cboIMITN_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboIMITN.ClickEvent

			If eventArgs.area = 2 Then
				txtIMITN.Text = cboIMITN.BoundText
				ISEDITING = False
				ButtonStatus()
				WriteToScreen((1))
				' cboIMITN.SelStart = 1
				cboIMITN.SelLength = 0
			End If
		End Sub

		Private Sub cboIMTYP_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboIMTYP.ClickEvent
			If eventArgs.area = 2 Then
				txtIMPGC.Focus()
			End If
		End Sub

		Private Sub cboIMTYP_KeyPressEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_KeyPressEvent) Handles cboIMTYP.KeyPressEvent
			If eventArgs.keyAscii = 13 Then
				txtIMPGC.Focus()
			End If
		End Sub

		Private Sub cboIMUMC_KeyPressEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_KeyPressEvent) Handles cboIMUMC.KeyPressEvent
			If eventArgs.keyAscii = 13 Then
				txtIMWPU.Focus()

			End If

		End Sub

		Private Sub cboIMVTC_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboIMVTC.ClickEvent
			If eventArgs.area = 2 Then
				txtIMVTC.Text = cboIMVTC.BoundText
				chkIMLOT.Focus()
			End If
		End Sub

		Private Sub cboIMVTC_KeyPressEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_KeyPressEvent) Handles cboIMVTC.KeyPressEvent
			If eventArgs.keyAscii = 13 Then
				chkIMLOT.Focus()
			End If
		End Sub

		Private Sub chkIMLOT_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles chkIMLOT.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				cmdSave.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub cmdAddnew_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAddnew.Click

			ISADDING = True
			ISEDITING = True
			WriteToScreen((0))
			Control((True))
			' Ham Gan tri man hinh
			ButtonStatus()
			'Frame1.Visible = True
			'Frame2.Visible = False

			txtIMITN.Focus()
		End Sub

		Private Sub cmdCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCancel.Click
			' Gan tri man nhinh
			ISADDING = False
			ISEDITING = False
			Control((False))
			ButtonStatus()
			txtIMITN.Text = cboIMITN.BoundText
			WriteToScreen((1))
			cmdAddnew.Focus()
		End Sub

		Private Sub cmdDelete_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdDelete.Click
			ISADDING = False
			ISEDITING = False
			' Ham delete theo Item chon
			Dim sql As String
			'SQL = "DELETE FROM IIM where imitn = '" & cboIMITN.BoundText & "'"
			sql = "Update IIM set IMRID='IZ' where imitn = '" & cboIMITN.BoundText & "'"
			DBconn.Execute(sql)
			Adodc4.Refresh()
			WriteToScreen((0))
			ButtonStatus()

		End Sub

		Private Sub cmdEdit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEdit.Click
			ISEDITING = True
			' Ham gan tri man hinh
			ISADDING = False
			ISEDITING = True
			Control((True))

			ButtonStatus()
		End Sub

		Private Sub cmdexit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExit.Click
			Me.Close()
		End Sub
		Private Sub WriteToScreen(ByRef tri As Byte)
			Dim TBL As ADODB.Recordset
			Dim recIRC As ADODB.Recordset
			If tri = 0 Then	'gan rong
				txtIMITN.Text = ""
				cboIMTYP.BoundText = ""
				txtIMWUM.Text = ""
				txtIMVPU.Text = CStr(0)
				txtIMSDC.Text = CStr(0)
				txtIMITD.Text = ""
				txtIMETD.Text = ""
				cboIMCLC.BoundText = "'"
				cboIMUMC.BoundText = ""
				txtIMWPU.Text = CStr(0)
				txtIMPER.Text = ""
				txtIMATC.Text = CStr(0)
				txtIMPRC.Text = CStr(0)
				txtIMLSZ.Text = CStr(0)
				txtIMROU.Text = CStr(0)
				txtIMOPC.Text = ""
				txtIMLTM.Text = CStr(0)
				txtIMVDC.Text = CStr(0)
				txtIMBSZ.Text = CStr(0)
				txtIMVTC.Text = ""
				txtIMPGC.Text = ""
				txtIMVTC.Text = ""
				cboIMVTC.defText = ""
				chkIMLOT.CheckState = System.Windows.Forms.CheckState.Unchecked
				txtRCED1.Text = ""
				txtRCED2.Text = ""
				txtRCED3.Text = ""
				txtRCVPU.Text = CStr(0)
				txtRCVUM.Text = ""
				txtRCPWG.Text = CStr(0)
			Else
				TBL = New ADODB.Recordset
				recIRC = New ADODB.Recordset
				TBL.Open("  Select IIM.* From IIM where  IMITN ='" & txtIMITN.Text & "'", DBconn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
				recIRC.Open("  Select IRC.* From IRC where  IMITN ='" & txtIMITN.Text & "'", DBconn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
				If recIRC.EOF = False Then
					txtRCED1.Text = IIf(IsDBNull(recIRC.Fields("IMED1").Value), "", recIRC.Fields("IMED1").Value)
					txtRCED2.Text = IIf(IsDBNull(recIRC.Fields("IMED2").Value), "", recIRC.Fields("IMED2").Value)
					txtRCED3.Text = IIf(IsDBNull(recIRC.Fields("IMED3").Value), "", recIRC.Fields("IMED3").Value)
					txtRCVPU.Text = IIf(IsDBNull(recIRC.Fields("IMVPU").Value), "", recIRC.Fields("IMVPU").Value)
					txtRCVUM.Text = IIf(IsDBNull(recIRC.Fields("IMVUM").Value), "", recIRC.Fields("IMVUM").Value)
					txtRCPWG.Text = IIf(IsDBNull(recIRC.Fields("IMPWG").Value), 0, recIRC.Fields("IMPWG").Value)
					recIRC.Close()
				Else
					txtRCED1.Text = ""
					txtRCED2.Text = ""
					txtRCED3.Text = ""
					txtRCVPU.Text = CStr(0)
					txtRCVUM.Text = ""
					txtRCPWG.Text = CStr(0)
					recIRC.Close()
				End If
				If TBL.EOF = False Then

					'txtIMITN = IIf(IsNull(TBL!imitn), "", TBL!imitn)
					cboIMITN.BoundText = txtIMITN.Text
					'cboIMTYP.BoundText = IIf(IsDBNull(TBL!imtyp), "", TBL!imtyp)
					cboIMTYP.BoundText = IIf(IsDBNull(TBL.Fields("imtyp").Value), "", TBL.Fields("imtyp").Value)
					txtIMWUM.Text = IIf(IsDBNull(TBL.Fields("imwum").Value), "", TBL.Fields("imwum").Value)
					txtIMVPU.Text = IIf(IsDBNull(TBL.Fields("IMVPU").Value), "", TBL.Fields("IMVPU").Value)
					txtIMSDC.Text = IIf(IsDBNull(TBL.Fields("imsdc").Value), "", TBL.Fields("imsdc").Value)
					txtIMITD.Text = IIf(IsDBNull(TBL.Fields("IMITD").Value), "", TBL.Fields("IMITD").Value)
					txtRCITD.Text = IIf(IsDBNull(TBL.Fields("IMITD").Value), "", TBL.Fields("IMITD").Value)
					txtIMETD.Text = IIf(IsDBNull(TBL.Fields("imetd").Value), "", TBL.Fields("imetd").Value)
					cboIMCLC.BoundText = IIf(TBL.Fields("imclc").Value, "", TBL.Fields("imclc").Value)
					cboIMUMC.BoundText = IIf(TBL.Fields("imumc").Value, "", TBL.Fields("imumc").Value)
					txtIMWPU.Text = IIf(TBL.Fields("IMWPU").Value, "", TBL.Fields("IMWPU").Value)
					txtIMPER.Text = IIf(TBL.Fields("IMPER").Value, "", TBL.Fields("IMPER").Value)
					txtIMATC.Text = IIf(TBL.Fields("IMATC").Value, "", TBL.Fields("IMATC").Value)
					txtIMPRC.Text = IIf(TBL.Fields("imprc").Value, "", TBL.Fields("imprc").Value)
					txtIMLSZ.Text = IIf(TBL.Fields("imlsz").Value, "", TBL.Fields("imlsz").Value)
					txtIMROU.Text = IIf(TBL.Fields("imrou").Value, "", TBL.Fields("imrou").Value)
					txtIMOPC.Text = IIf(TBL.Fields("IMOPC").Value, "", TBL.Fields("IMOPC").Value)
					txtIMLTM.Text = IIf(IsDBNull(TBL.Fields("imltm").Value), "", TBL.Fields("imltm").Value)
					txtIMVDC.Text = IIf(IsDBNull(TBL.Fields("imvdc").Value), "", TBL.Fields("imvdc").Value)
					txtIMBSZ.Text = IIf(IsDBNull(TBL.Fields("imbsz").Value), "", TBL.Fields("imbsz").Value)
					txtIMVTC.Text = IIf(IsDBNull(TBL.Fields("IMVTC").Value), "", TBL.Fields("IMVTC").Value)
					txtIMPGC.Text = IIf(IsDBNull(TBL.Fields("IMPGC").Value), "", TBL.Fields("IMPGC").Value)
					txtIMVTC.Text = IIf(IsDBNull(TBL.Fields("IMVTC").Value), "", TBL.Fields("IMVTC").Value)
					cboIMVTC.BoundText = IIf(IsDBNull(TBL.Fields("IMVTC").Value), "", TBL.Fields("IMVTC").Value)
					chkIMLOT.CheckState = IIf(TBL.Fields("imwum").Value, 1, 0)
				Else
					txtIMITN.Text = ""
					cboIMTYP.BoundText = ""
					txtIMWUM.Text = ""
					txtIMVPU.Text = CStr(0)
					txtIMSDC.Text = CStr(0)
					txtIMITD.Text = ""
					txtIMETD.Text = ""
					cboIMCLC.BoundText = "'"
					cboIMUMC.BoundText = ""
					txtIMWPU.Text = CStr(0)
					txtIMPER.Text = ""
					txtIMATC.Text = CStr(0)
					txtIMPRC.Text = CStr(0)
					txtIMLSZ.Text = CStr(0)
					txtIMROU.Text = CStr(0)
					txtIMOPC.Text = ""
					txtIMLTM.Text = CStr(0)
					txtIMVDC.Text = CStr(0)
					txtIMBSZ.Text = CStr(0)
					txtIMVTC.Text = ""
					txtIMVTC.Text = ""
					cboIMVTC.BoundText = ""
					chkIMLOT.CheckState = System.Windows.Forms.CheckState.Unchecked
				End If
				TBL.Close()
			End If
			OldIMITN = txtIMITN.Text
		End Sub
		Private Sub WriteToFile(ByRef tri As Byte)
			Dim recIRC As Object
			Dim SQLInsert As String
			If tri = 0 Then
				SQLInsert = " INSERT INTO IIM " & "(IMITN,IMTYP,IMWUM,IMVPU,IMSDC,IMITD,IMCLC,IMUMC,IMWPU,IMPER" & ",IMATC,IMPRC,IMLSZ,IMROU,IMOPC,IMLTM,IMVDC,IMBSZ,IMVTC,IMETD,IMPGC" & ",IMOBU,IMRCU,IMISU,IMAJU,IMSLU,IMOOU,IMCOU,IMALU,IMYSU,IMYIU" & ",IMOBW,IMRCW,IMISW,IMAJW,IMSLW,IMOOW,IMCOW,IMALW,IMYSW,IMYIW" & ",IMLOT,IMRID,IMLDT,IMLUS,IMTSQ,IMWSQ) " & "VALUES " & "('" & txtIMITN.Text & "', '" & cboIMTYP.BoundText & "', '" & txtIMWUM.Text & "', " & Val(txtIMVPU.Text) & ", " & Val(txtIMSDC.Text) & ", '" & txtIMITD.Text & "', '" & cboIMCLC.BoundText & "', '" & cboIMUMC.BoundText & "', " & Val(txtIMWPU.Text) & ", '" & VB.Left(txtIMPER.Text, 3) & "', " & Val(txtIMATC.Text) & ", " & Val(txtIMPRC.Text) & ", " & Val(txtIMLSZ.Text) & ", " & Val(txtIMROU.Text) & ", '" & VB.Left(txtIMOPC.Text, 1) & "', " & Val(txtIMLTM.Text) & ", " & Val(txtIMVDC.Text) & ", " & Val(txtIMBSZ.Text) & ", '" & txtIMVTC.Text & "', '" & txtIMETD.Text & "', '" & VB.Left(txtIMPGC.Text, 5) & "'" & ",0,0,0,0,0,0,0,0,0,0" & ",0,0,0,0,0,0,0,0,0,0," & chkIMLOT.CheckState & ",'IM','" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "','" & UserLogin & "',0,0)"
				DBconn.Execute(SQLInsert)
				SQLInsert = "Insert into IRC " & "(IMITN,IMITD,IMED1,IMED2,IMED3,IMVPU,IMVUM,IMPWG)" & "VALUES " & "('" & txtIMITN.Text & "', '" & txtIMITD.Text & "', '" & txtRCED1.Text & "', '" & txtRCED2.Text & "', '" & txtRCED3.Text & "', '" & txtRCVPU.Text & "', '" & txtRCVUM.Text & "', '" & txtRCPWG.Text & "')"
				DBconn.Execute(SQLInsert)
			Else
				SQLInsert = "UPDATE IIM SET " & "IMITN ='" & txtIMITN.Text & "', IMTYP ='" & cboIMTYP.BoundText & "', " & "IMWUM ='" & txtIMWUM.Text & "', IMVPU =" & Val(txtIMVPU.Text) & ", " & "IMSDC = " & Val(txtIMSDC.Text) & ", IMITD = '" & txtIMITD.Text & "', " & "IMCLC ='" & cboIMCLC.BoundText & "', IMUMC ='" & cboIMUMC.BoundText & "', " & "IMWPU =" & Val(txtIMWPU.Text) & ", IMPER = '" & VB.Left(txtIMPER.Text, 3) & "', " & "IMATC =" & Val(txtIMATC.Text) & ", IMPRC =" & Val(txtIMPRC.Text) & ", " & "IMLSZ =" & Val(txtIMLSZ.Text) & ", IMROU =" & Val(txtIMROU.Text) & ", " & "IMOPC ='" & VB.Left(txtIMOPC.Text, 1) & "', IMLTM =" & Val(txtIMLTM.Text) & ", " & "IMVDC = " & Val(txtIMVDC.Text) & ", IMBSZ =" & Val(txtIMBSZ.Text) & ", " & "IMVTC ='" & txtIMVTC.Text & "', IMETD ='" & txtIMETD.Text & "', " & "IMPGC = '" & VB.Left(txtIMPGC.Text, 5) & "',IMLOT=" & chkIMLOT.CheckState & ",IMLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "',IMLUS='" & UserLogin & "'" & " WHERE IMITN ='" & OldIMITN & "'"
				DBconn.Execute(SQLInsert)

				'///////////////////////////////////

				recIRC = New ADODB.Recordset
				recIRC.Open("  Select IRC.* From IRC where  IMITN ='" & txtIMITN.Text & "'", DBconn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
				If recIRC.EOF = False Then
					SQLInsert = "UPDATE IRC set " & "IMITN='" & txtIMITN.Text & "',IMITD='" & txtIMITD.Text & "',IMED1='" & txtRCED1.Text & "',IMED2='" & txtRCED2.Text & "',IMED3='" & txtRCED3.Text & "',IMVPU='" & txtRCVPU.Text & "',IMVUM='" & txtRCVUM.Text & "',IMPWG='" & txtRCPWG.Text & "' " & " WHERE IMITN ='" & OldIMITN & "'"
					DBconn.Execute(SQLInsert)
					recIRC.Close()
				Else
					SQLInsert = "Insert into IRC " & "(IMITN,IMITD,IMED1,IMED2,IMED3,IMVPU,IMVUM,IMPWG)" & "VALUES " & "('" & txtIMITN.Text & "', '" & txtIMITD.Text & "', '" & txtRCED1.Text & "', '" & txtRCED2.Text & "', '" & txtRCED3.Text & "', '" & txtRCVPU.Text & "', '" & txtRCVUM.Text & "', '" & txtRCPWG.Text & "')"
					DBconn.Execute(SQLInsert)
					recIRC.Close()
				End If



			End If

			'DBconn.Execute SQLInsert

		End Sub
		Private Sub cmdSave_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSave.Click
			' Ham Save tri vao file
			Dim tbl_ChapNhan As ADODB.Recordset
			tbl_ChapNhan = New ADODB.Recordset
			tbl_ChapNhan.Open("  Select IIM.* From IIM ", DBconn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
			tbl_ChapNhan.Close()
			If ISADDING = False Then
				WriteToFile((1))
			Else
				WriteToFile((0))
			End If
			Adodc4.Refresh()
			Control((False))
			'''''''''''
			ISADDING = False
			ISEDITING = False

			ButtonStatus()
			cmdAddnew.Focus()
		End Sub

		Private Sub frmINV100_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
			If Not InitSuccess Then
				BIENCHUNG()
			End If

			Adodc1.ConnectionString = ConnectString
			Adodc1.ConnectionTimeout = 10
			Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdTable
			Adodc1.RecordSource = "ICL"	'ITEM CLASSE
			Adodc1.Refresh()

			Adodc2.ConnectionString = ConnectString
			Adodc2.ConnectionTimeout = 10
			Adodc2.CommandType = ADODB.CommandTypeEnum.adCmdTable
			Adodc2.RecordSource = "ITP"	'ITEM type
			Adodc2.Refresh()

			Adodc3.ConnectionString = ConnectString
			Adodc3.ConnectionTimeout = 10
			Adodc3.CommandType = ADODB.CommandTypeEnum.adCmdTable
			Adodc3.RecordSource = "IUM"	'unit of measure
			Adodc3.Refresh()

			Adodc4.ConnectionString = ConnectString
			Adodc4.ConnectionTimeout = 10
			Adodc4.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc4.RecordSource = "Select IMITN,IMITN +' : ' +IMITD   as IMITD from IIM where IMRID <>'IZ' order by imitn" 'unit of measure
			Adodc4.Refresh()

			Adodc5.ConnectionString = ConnectString
			Adodc5.ConnectionTimeout = 10
			Adodc5.CommandType = ADODB.CommandTypeEnum.adCmdTable
			Adodc5.RecordSource = "VVT"	'unit of measure
			Adodc5.Refresh()
			'Adodc6.ConnectionString = ConnectString
			'Adodc6.ConnectionTimeout = 10
			'Adodc6.CommandType = adCmdTable
			'Adodc6.RecordSource = "IRC" 'Label
			'Adodc6.Refresh
			ISADDING = False
			ISEDITING = False
			ButtonStatus()
			Frame2.Visible = False
			VB6_AddADODataBinding()
			Me.cboIMITN.RowSource = Me.ADOBind_Adodc4.DataSource
			Me.cboIMCLC.RowSource = Me.ADOBind_Adodc1.DataSource
			Me.cboIMUMC.RowSource = Me.ADOBind_Adodc3.DataSource
			Me.cboIMVTC.RowSource = Me.ADOBind_Adodc5.DataSource

		End Sub

		Sub ButtonStatus()
			cmdAddnew.Enabled = Not ISEDITING
			cmdEdit.Enabled = Not ISEDITING
			cmdSave.Enabled = ISEDITING	' And txtIMITN <> ""
			cmdDelete.Enabled = Not ISEDITING 'And txtIMITN <> ""
			cmdCancel.Enabled = ISEDITING
			'txtIMITN.Locked = Not ISADDING ' Lock item code tru truong hop ISADDING=true
			Frame1.Enabled = ISEDITING
			'txtDepartment.Enabled = ISEDITING
			'cboDepartment.Visible = Not ISADDING
			'txtDepartmentID.Visible = ISADDING
		End Sub


		Private Sub TabStrip1_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles TabStrip1.ClickEvent
			If TabStrip1.SelectedItem.Index = 1 Then ' No need to change frame.
				' Otherwise, hide old frame, show new.
				Frame1.Visible = True
				Frame2.Visible = False
				If ISEDITING = False Then
					cmdAddnew.Enabled = True
				End If
			Else


				'Control (True)
				' Ham Gan tri man hinh
				cmdAddnew.Enabled = False

				Frame1.Visible = False
				Frame2.Visible = True
				' Set mintCurFrame to new value.
				' mintCurFrame = TabStrip1.SelectedItem.Index
			End If
		End Sub

		Private Sub txtIMATC_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMATC.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMLSZ.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMBSZ_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMBSZ.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMITD.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMETD_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMETD.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				cboIMCLC.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMITD_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMITD.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMETD.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMITN_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMITN.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				If ISEDITING Then
					If ValidMaso(OldIMITN, txtIMITN, "IIM", " IMITN='" & txtIMITN.Text & "'") Then
						MsgBox("This code is already exist")
						txtIMITN.Focus()
					Else
						cboIMTYP.Focus()
					End If
				Else
					'txtIMITN = cboIMITN.BoundText
					' ISEDITING = False
					If Find("IIM", "IMITN", " WHERE IMITN='" & txtIMITN.Text & "'") = "" Then
						MsgBox("This Item doesn't exist")
						cboIMITN.Focus()
						GoTo EventExitSub
					End If

					ButtonStatus()
					WriteToScreen((1))
				End If
			End If
EventExitSub:
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMLSZ_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMLSZ.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMOPC.Focus()
			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMLTM_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMLTM.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMBSZ.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMOPC_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMOPC.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMVDC.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMPER_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMPER.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMATC.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMPGC_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMPGC.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMWUM.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMPRC_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMPRC.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMROU.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMROU_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMROU.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMLTM.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMSDC_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMSDC.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMPRC.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMVDC_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMVDC.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				cboIMVTC.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMVPU_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMVPU.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMSDC.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMWPU_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMWPU.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMPER.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtIMWUM_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtIMWUM.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				txtIMVPU.Focus()

			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub


	End Class
End Namespace